package com.aptemo.webetek.client.widgets;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Lists item horizontally splitting them with a "|" sign
 */
public class HorizontalMenu
		extends HorizontalPanel
{
	private static final String	HTML_NON_BRAKING_SPACE	= "&nbsp;";

	public HorizontalMenu()
	{
	}

	@Override
	public void add(Widget item)
	{
		if (getWidgetCount() >= 1)
			super.add(getSplitter());
		super.add(item);
	}

	@Override
	public boolean remove(Widget w)
	{
		return super.remove(w);
	}

	public static HTML getSplitter()
	{
		return new HTML(HTML_NON_BRAKING_SPACE + "|" + HTML_NON_BRAKING_SPACE);
	}

	public void setMenuItemVisible(boolean visible, Widget w)
	{
		int index = getWidgetIndex(w);
		w.setVisible(visible);
		if (getWidgetCount() >= 1 && index > 0)
		{
			Widget splitter = getWidget(index - 1);
			splitter.setVisible(visible);
		}
		int s = getWidgetCount();
		for (int i = 0; i < s; i++)
		{
			Widget wi = getWidget(i);
			if (wi instanceof HTML && wi.isVisible())
			{
				wi.setVisible(false);
				return;
			}
			else
			{
				return;
			}
		}

	}
}
